﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Domain;
using Warehouse.Domain.DTO;
using Warehouse.Read.API.Applcation.Command.AllocateCommand;
using Warehouse.Read.API.Applcation.Command.InjureCommand;
using Warehouse.Read.API.Dtos;

namespace Warehouse.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class AllocateController : ControllerBase
    {
        IMediator mediator;

        public AllocateController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 反填调拨
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Allocate>> FanAllocateList([FromQuery] AllocateFanCommand command)
        {
            Dtos.ApiResult<Allocate> result = new Dtos.ApiResult<Allocate>();

            try
            {
                result.Code = 200;
                result.Message = "反填调拨";
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 显示调拨列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<AllProductListDTO>>> GetAllocateList([FromQuery] AllocateListCommand command)
        {
            Dtos.ApiResult<PageDTO<AllProductListDTO>> result = new Dtos.ApiResult<PageDTO<AllProductListDTO>>();

            try
            {
                result.Code = 200;
                result.Message = "显示调拨列表";
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示查看详情调拨列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<AllProductListDTO>>> GetAllocateInquireList([FromQuery] AllocateInquireListCommand command)
        {
            Dtos.ApiResult<List<AllProductListDTO>> result = new Dtos.ApiResult<List<AllProductListDTO>>();

            try
            {
                result.Code = 200;
                result.Message = "显示调拨列表";
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }




    }
}
